﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Com.LongER.Framework.Utils.LogUtils;
using Com.LongER.Framework.Utils;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace Com.LongER.UI
{
    /// <summary>
    ///ABasePage 的摘要说明
    /// </summary>
    public abstract class ABasePage : System.Web.UI.Page
    {
        protected const String CSS_TEXT_ERROR = "txt_error";
        

        /// <summary>
        /// 为元素添加指定的CSS
        /// </summary>
        /// <param name="ctl"></param>
        /// <param name="css"></param>
        protected void AddCssClass(System.Web.UI.WebControls.WebControl ctl, String css)
        {
            //
            if (css.Equals(String.Empty)) return;

            ctl.CssClass = ctl.CssClass + " " + css;
        }

        /// <summary>
        /// 从元素中删除全部或者指定的CSS
        /// </summary>
        /// <param name="ctl"></param>
        /// <param name="css"></param>
        protected void RemoveCssClass(System.Web.UI.WebControls.WebControl ctl, String css)
        {
            //
            if (css.Equals(String.Empty)) ctl.CssClass = "";

            ctl.CssClass = ctl.CssClass.Replace(" " + css, String.Empty);
        }

        /// <summary>
        /// 从元素中删除全部的CSS
        /// </summary>
        /// <param name="ctl"></param>
        protected void RemoveCssClass(System.Web.UI.WebControls.WebControl ctl)
        {
            RemoveCssClass(ctl, String.Empty);
        }

        /// <summary>
        /// 
        /// </summary>
        protected enum MSG_LEVEL
        {
            [Description("message level is information.")]
            Info,
            [Description("message level is warning.")]
            Warn,
            [Description("message level is error.")]
            Error
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ModuleName"></param>
        /// <param name="MessageId"></param>
        /// <param name="MessageLevel"></param>
        protected void SetMessage(String ModuleName, String MessageId, MSG_LEVEL MessageLevel)
        {

            String msg = MessageUtil.GetMessage(ModuleName, MessageId);

            Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
            lblMsgCD.Text = MessageId;
            this.RemoveCssClass(lblMsgCD);
            this.AddCssClass(lblMsgCD, "SITE_msg_" + MessageLevel.ToString());

            Label lblMsg = (Label)Master.FindControl("lblMsg");
            lblMsg.Text = msg;
            this.RemoveCssClass(lblMsg);
            this.AddCssClass(lblMsg, "SITE_msg_" + MessageLevel.ToString());

        }


        /// <summary>
        /// 
        /// </summary>
        public ABasePage()
            : base()
        {
        }
    }
}